<template>
	<view>
		<radio-group @change="changeRadio" class="radioBox">
			<radio style="padding:20rpx ;" v-for="(item,index) in pickerList" :value="item.id" :checked="index == 0">{{item.name}}</radio>
		</radio-group>
	</view>
</template>

<script>
export default {
	data() {
		return {
			pickerList:[],
			selIdx:0,
		};
	},
	props: {
		list: {
			type: Array,
			default: () => []
		},
		keyName:{
			type: String,
			default: 'name'
		},
		idName:{
			type: String,
			default: 'id'
		},
		name:{
			type: String,
			default: ''
		},
		listName:{
			type: String,
			default: ''
		},
		form:{
			type: Object,
			default: ()=>{}
		}
	},
	mounted() {
		this.pickerList  = this.$store.state[this.listName] || this.list || [];
		// 需要在dom刷新完成之后进行默认值赋予, 不然会有问题
		this.$nextTick(function(){
			this.form.setValue(this.name,this.pickerList[0][this.idName]);
		})
	},
	methods: {
		changeRadio (e){
			this.selIdx = e.detail.value;
			this.form.setValue(this.name,this.pickerList[this.selIdx][this.idName])
		}
	}
};
</script>

<style lang="scss" scoped>
	.radioBox{
		width: 100%;
	}
</style>
